home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 228_01 / systmisc.c < prev   
Encoding:
Text File  |  1987-07-29  |  3.6 KB  |  109 lines

  1. /*
  2. HEADER:         CUGXXX;
  3. TITLE:          (MS-DOS) System-independent sound generation;
  4. DATE:           10-30-84;
  5. DESCRIPTION:    System functions to create sounds using system time/date;
  6. KEYWORDS:       Sound generation, system functions;
  7. FILENAME:       SYSTMISC.C;
  8. WARNINGS:       IBM-PC and close compatibles;
  9. AUTHORS:        Garth Kennedy;
  10. COMPILER:       Lattice C V2.12;
  11. REFERENCES:     US-DISK 1310;
  12. ENDREF
  13. */
  14. /**
  15. * This is a collection of system functions that get the
  16. * system time and date and create a sound from the internal
  17. * speaker. This is written in the Lattice 2.12 compiler
  18. * and is taken from a larger program
  19. *
  20. * Garth Kennedy    Hinsdale, Ill    9 Nov 1984
  21. **/
  22.  
  23.  
  24. int tme[10];               /* time date array */
  25. /**
  26. *         tme[0] - day of week (0-6) (sun- sat)
  27. *         tme[1] - hours (0-23)
  28. *         tme[2] - minutes (0-59)
  29. *         tme[3] - Seconds (0-59)
  30. *         tme[4] - 100s of seconds (0-99)
  31. *         tme[6] - year (1980 - 2099)
  32. *         tme[7] - month (1-12)
  33. *         tme[8] - day of month (1-31)
  34. **/
  35.  
  36. /**
  37. * sound(freq,tlen)
  38. *
  39. * set the frequency of the speaker
  40. * the passed parameter <freq> is the frequency in Hz
  41. *               <tlen> is the duration of the sound
  42. *               each increment of <tlen> is approximately
  43. *               20 ms on my IBM PC-I
  44. *  had to use machine locations here - couldnt see how to get at
  45. *  this within DOS.
  46. *
  47. * Garth Kennedy   30 Oct 1984
  48. *
  49. **/
  50.  
  51. sound(freq,tlen)
  52. int freq;      /* freq of sound in Hertz */
  53. int tlen;      /* duration of sound arbitrary units    */
  54. {
  55.     unsigned frdiv = 1331000L/freq;   /* timer divisor */
  56.     int i,j,k;
  57.  
  58.     outp(0x43,0xB6);           /* write timer mode register */
  59.     outp(0x42,frdiv & 0x00FF);    /* write divisor LSB */
  60.     outp(0x42,frdiv >> 8);    /* write divisor MSB */
  61.  
  62.     i = inp(0x61);        /* get current port B setting */
  63.     outp(0x61,i | 0x03);    /* turn speaker on */
  64.     for ( j = 0;j <= tlen; j++)
  65.     {                /* loop till timed out */
  66.     for (k = 0; k < 1000;k++)
  67.     ;
  68.     }
  69.     outp(0x61,i);        /* restore port B setting */
  70.                 /* turn speaker off */
  71.     return;
  72. }
  73.  
  74. /**/
  75. /**
  76. * gtime(tme)
  77. *
  78. * Get the time from the system
  79. * return time in the integer array tme[]
  80. *         tme[0] - day of week (0-6) (sun- sat)
  81. *         tme[1] - hours (0-23)
  82. *         tme[2] - minutes (0-59)
  83. *         tme[3] - Seconds (0-59)
  84. *         tme[4] - 100s of seconds (0-99)
  85. *
  86. * Garth Kennedy  31 Oct 1984
  87. **/
  88. gtime(tme)
  89. int tme[];
  90. {
  91.     int intno = 0x21;          /* interrupt number (DOS Function Call) */
  92.     union REGS inregs;          /* input registers */
  93.     union REGS outregs;       /* output registers */
  94.  
  95.     inregs.h.ah = 0x2C;       /* function number for get time */
  96.     int86(intno,&inregs,&outregs);   /* make function call */
  97.     tme[0] = outregs.h.al;         /* day of the week */
  98.     tme[1] = outregs.h.ch;         /* hours */
  99.     tme[2] = outregs.h.cl;         /* minutes */
  100.     tme[3] = outregs.h.dh;         /* seconds */
  101.     tme[4] = outregs.h.dl;         /* 1/100 seconds */
  102.     return;
  103. }
  104. /**
  105. * gdate()
  106. *
  107. * Get the date from the system
  108. * return date in the integer array tme[]
  109. *         tme[6] -